package com.xywy.wjk.adapter;

import java.util.List;

import com.xywy.R;
import com.xywy.wjk.bean.WeightDetail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class WeightDetailAdapter extends BaseAdapter {

	private List<WeightDetail> list;
	private LayoutInflater inflater;

	public WeightDetailAdapter(List<WeightDetail> list, Context context) {
		super();
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			// 获取ViewHolder对象
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.wjk_detail_listview_item,
					null);
			holder.ItemIcon = (ImageView) convertView
					.findViewById(R.id.iv_detail_data_icon);
			holder.ItemName = (TextView) convertView
					.findViewById(R.id.tv_detail_data_name);
			holder.ItemValue = (TextView) convertView
					.findViewById(R.id.tv_detail_data_value);
			holder.ItemValueRate = (TextView) convertView
					.findViewById(R.id.tv_detail_data_value_rate);
			holder.ItemState = (TextView) convertView
					.findViewById(R.id.tv_detail_data_state);
			convertView.setTag(holder);
		} else {
			// 取出holder
			holder = (ViewHolder) convertView.getTag();

		}
		holder.ItemIcon.setImageResource(list.get(position).getItemIcon());
		holder.ItemName.setText(list.get(position).getItemName());
		holder.ItemValue.setText(list.get(position).getItemValue().toString());
		if (list.get(position).getItemValue() == 0.0) {
			holder.ItemState.setVisibility(View.GONE);
		}else {
			holder.ItemState.setVisibility(View.VISIBLE);
		}
		holder.ItemValueRate.setText(list.get(position).getItemValueRate()
				.toString());
		holder.ItemState.setText(list.get(position).getItemState());
		if ("偏低".equals(list.get(position).getItemState())) {
			holder.ItemState
					.setBackgroundResource(R.drawable.shape_lower_text_background);
		} else if ("偏高".equals(list.get(position).getItemState())) {
			holder.ItemState
					.setBackgroundResource(R.drawable.shape_higher_text_background);
		}

		return convertView;
	}

	public class ViewHolder {
		private int position;
		private ImageView ItemIcon;
		private TextView ItemName;
		private TextView ItemValue;
		private TextView ItemValueRate;
		private TextView ItemState;

	}

}
